package cn.gson.boot.controller;

import cn.gson.boot.model.pojos.Gong;
import cn.gson.boot.model.pojos.Role;
import cn.gson.boot.model.pojos.Sort;
import cn.gson.boot.model.service.RoleService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("roles")
public class RoleController {
    @Autowired
    RoleService roleService;

    //查询所有角色
    @RequestMapping("role-list")
    @ResponseBody
    public Map<String,Object> roleList(Integer Size, Integer Num,String searchOne){
        Page<Object> object= PageHelper.startPage(Size,Num);
        List<Role> users = roleService.roleList(searchOne);
        System.out.println("ss"+object.getTotal());
        Map<String,Object> map=new HashMap<>();
        map.put("object2",object.getTotal());
        map.put("row2",object.getResult());
        return map;
    }

    //新增角色
    @RequestMapping("/save-role")
    @ResponseBody
    public void saveEmp(@RequestBody Role role){
        roleService.saveRole(role);
    }
    //查询功能组表中所有功能的功能
    @RequestMapping("gong-list")
    @ResponseBody
    public List<Gong> gongList2(Integer deptId){
        return roleService.gongList2(deptId);
    }

    //根据角色查询此角色所有的功能
    @RequestMapping("role-fun")
    @ResponseBody
    public List<Integer> roleFunList(Integer jueId){
        for(int i=0;i<roleService.roleFunList(jueId).size();i++){
            System.out.println(roleService.roleFunList(jueId).get(i));
        }
        System.out.println(roleService.roleFunList(jueId));
        return roleService.roleFunList(jueId);
    }

    //修改角色的功能组
    @RequestMapping("shouquan")
    @ResponseBody
    public void shouquan(Integer jueId,String gnList){
        roleService.shouquan(jueId,gnList);
    }



    @RequestMapping("gongnengzuName")
    @ResponseBody
    //查询功能组的名称
    public List<String> gongnengzuName(){
        return roleService.gongnengzuName();
    }

    //根据功能组名称查询功能
    @RequestMapping("gongnengList")
    @ResponseBody
    public List<Gong> gongnengList(String gnName){
        return roleService.gongnengList(gnName);
    }


    //查看所有的功能
    @RequestMapping("selectAllGongNeng")
    @ResponseBody
    public List<Sort> selectAllGongNeng(String gnzName){
        return roleService.selectAllGongNeng(gnzName);
    }
    //根据功能组名称查询此功能组所有的功能
    @RequestMapping("selectGongNengBygnzuName")
    @ResponseBody
    public List<Integer> selectGongNengBygnzuName(String gnzName){
        return roleService.selectGongNengBygnzuName(gnzName);
    }

    //修改功能组的功能
    @RequestMapping("updateGnZuGn")
    @ResponseBody
    public void updateGnZuGn(String gnzName,String gnList){
        roleService.updateGnZuGn(gnzName,gnList);
    }

}
